package com.captain.special.数组;

/**
 * Des:
 *
 * @author XL
 * @Date 2022/4/4 10:13
 */
public class 二分查找704 {

    public int search(int[] nums, int target) {
        int left = 0;
        //[left , right]
        int right = nums.length - 1;

        while (left <= right) {
            int mid = left + ((right - left) / 2);
            int midValue = nums[mid];
            if (midValue < target) {
                left = mid + 1;
            } else if (midValue > target) {
                right = mid - 1;
            } else {
                return mid;
            }
        }
        return -1;
    }
}
